<?php
header('content-type:text/html;charset=utf-8');
function getTree($array){
	$tree = array();
	foreach($array as $v){
		if(isset($array[$v['pid']])){
			$array[$v['pid']]['son'][] = &$array[$v['id']];
		} else {
			$tree[] = &$array[$v['id']];
		}
	}
	return $tree;
}
$array = array(  
    1 => array('id' => 1, 'pid' => 0, 'name' => '安徽省'),    
    2 => array('id' => 2, 'pid' => 0, 'name' => '浙江省'),    
    3 => array('id' => 3, 'pid' => 1, 'name' => '合肥市'),    
    4 => array('id' => 4, 'pid' => 3, 'name' => '长丰县'),  
  
    5 => array('id' => 5, 'pid' => 1, 'name' => '安庆市'),   
);  
echo '<pre/>'; 
print_r(getTree($array));  